package ListNodeSecond.SwordOffer;

import java.math.BigDecimal;
import java.util.ArrayDeque;
import java.util.Deque;

public class AddTwoNumbers {

    public static ListNode addTwoNumbers(ListNode l1, ListNode l2) {

        ListNode ans = null;
        Deque<Integer> stack1 = new ArrayDeque<Integer>();
        Deque<Integer> stack2 = new ArrayDeque<Integer>();
        while (l1 != null) {
            stack1.push(l1.val);
            l1 = l1.next;
        }
        while (l2 != null) {
            stack2.push(l2.val);
            l2 = l2.next;
        }
        int carry = 0;
        while (!stack1.isEmpty() || !stack1.isEmpty() || carry != 0) {
            //3427
            //465
            int val1 = stack1.isEmpty() ? 0 : stack1.pop();
            int val2 = stack2.isEmpty() ? 0 : stack2.pop();
            int sum = val1 + val2 + carry;
            carry = sum / 10;
            //7087
            ListNode curnode = new ListNode(sum % 10);
            curnode.next = ans;
            ans = curnode;
        }
        return ans;
    }

    /**
     * Deque<Integer> stack1 = new ArrayDeque<Integer>();
     * Deque<Integer> stack2 = new ArrayDeque<Integer>();
     * while (l1 != null) {
     * stack1.push(l1.val);
     * l1 = l1.next;
     * }
     * while (l2 != null) {
     * stack2.push(l2.val);
     * l2 = l2.next;
     * }
     * int carry = 0;
     * ListNode ans = null;
     * while (!stack1.isEmpty() || !stack2.isEmpty() || carry != 0) {
     * int a = stack1.isEmpty() ? 0 : stack1.pop();
     * int b = stack2.isEmpty() ? 0 : stack2.pop();
     * int cur = a + b + carry;
     * carry = cur / 10;
     * cur %= 10;
     * ListNode curnode = new ListNode(cur);
     * curnode.next = ans;
     * ans = curnode;
     * }
     * return ans;
     */
    public static void main(String[] args) {
        //[7,2,4,3]
        //  [5,6,4]
        //[7,8,0,7]
//        ListNode node1 = new ListNode(7);
//        ListNode node2 = new ListNode(2);
//        ListNode node3 = new ListNode(4);
//        ListNode node4 = new ListNode(3);
//
//        node1.next = node2;
//        node2.next = node3;
//        node3.next = node4;
//
//        ListNode nodeList1 = new ListNode(5);
//        ListNode nodeList2 = new ListNode(6);
//        ListNode nodeList3 = new ListNode(4);
//
//        nodeList1.next = nodeList2;
//        nodeList2.next = nodeList3;
//
//        System.out.println(addTwoNumbers(node1, nodeList1));

        String sql = "with ( SELECT groupBitmapAndState(suid) AS count from ( select groupBitmapOrState(suid) as suid  from app_scrm_suid_flag_bigint_dt_da_aggregation where tenant_brand_code = ? and key = ? and value in ( ?,?,? ) UNION ALL select groupBitmapOrState(suid) as suid  from app_scrm_suid_flag_bigint_dt_da_aggregation where tenant_brand_code = ? and key = ? and value = ? ) ) as a, ( SELECT groupBitmapOrState(suid) AS count from ( select groupBitmapOrState(suid) as suid  from app_scrm_suid_flag_bigint_dt_da_aggregation where tenant_brand_code = ? and key = ? and value = ? UNION ALL select bitmapBuild(groupArray(toUInt64(suid))) as suid from (select suid,count(suid) as aggregate_value from app_scrm_suid_order_detail_dt_de where tenant_brand_code = ? and dt >= ? and dt <= ? and event_type = ? group by suid)  where aggregate_value > ? and aggregate_value < ? ) ) as b select bitmapToArray(bitmapOr(a, b)) as count";
        Object[] params = {"1000", "age_stage", 1, 2, 3, "1000", "certificate_label", 1, "1000", "is_black_gold", 1, "1000", "2022-05-03", "2022-06-02", 1, 100, 300};
        String sql1 = "select * from app_scrm_suid_flag_bigint_dt_da_aggregation where key = ?";
        Object[] params1 = {1};
//        StrSubstitutor strSubstitutor = new StrSubstitutor(map);
        String s ="100,";
        String[] split = s.split(",");
        for (int i = 0; i < split.length; i++) {
            System.out.println(split[i]);
        }

    }
}
